﻿using Halcon二次开发.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 可视化工具.View.输入框
{
    public partial class ANewProjectForm : Form
    {
        //要修改的工程名
        public string verifyName = "";
        //初始路径
        public string path="";
        public ANewProjectForm(string verifyName,string path)
        {
            InitializeComponent();
            this.verifyName = verifyName;
            this.path = path;   
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string oldProbjectPath = path + verifyName;
            if (textBox1.Text == "" || StaicResouce.projectList.Contains(textBox1.Text))
            {
                MessageBox.Show("文件名称为空或重复文件名称!");
                this.Close();
                return;
            }
            string newProbjectPath = path + textBox1.Text; 
            int idenxt = StaicResouce.projectList.IndexOf(verifyName);
            if (idenxt!=-1)
            {
                StaicResouce.projectList[idenxt] = textBox1.Text;//修改集合当中的工程名称
                //修改文件当中的文件名
                try
                {
                    // 检查原文件夹是否存在
                    if (Directory.Exists(oldProbjectPath))
                    {
                        // 使用 Directory.Move 方法重命名文件夹
                        Directory.Move(oldProbjectPath, newProbjectPath);
                    }
                    else
                    {
                        
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"重命名文件夹时出错: {ex.Message}");
                }
                //修改每个自定义控件中的所属工程名


            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
